package com.lagou.homework3_1;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

/**
 * Reduce类
 */
public class SortReducer extends Reducer<Number, NullWritable, NullWritable, Text> {

    /**
     * 重写reduce方法
     * @param key
     * @param values
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void reduce(Number key, Iterable<NullWritable> values, Context context) throws IOException, InterruptedException {
        System.out.printf("进入reduce---------------");
        int sort = 0;
        Text res = new Text();
        for (NullWritable value : values) {
            sort++;
            res.set(sort + "\t" + key.getNum());
            context.write(NullWritable.get(), res);
        }
    }
}
